<?php

	// TITLE: Home_owner_debt AUTO MODEL
	// FILE: scaffolding/model/home_owner_debt.php
	// AUTHOR: AUTOGEN
	// CREATED: 2015/04/20 07:49:57
	// DESCRIPTION: 
	// REQUIREMENTS: 

	$createHomeOwnerDebt = function($con, $homeOwnerDebt) {
		$sql = 'INSERT INTO home_owner_debt (id, ho_id, debter_id, monthly_payment, balance) VALUES (';
		$sql .= $home_owner_debt->getId() . ', ';
		$sql .= $home_owner_debt->getHoId() . ', ';
		$sql .= $home_owner_debt->getDebterId() . ', ';
		$sql .= $home_owner_debt->getMonthlyPayment() . ', ';
		$sql .= $home_owner_debt->getBalance() . ')';
		$sql .= ')';
		$result = mysqli_query($con, $sql);
		$id = ($result) ? mysqli_insert_id($con) : $result;
		mysqli_close($con);
		return $id;
	};

	$readHomeOwnerDebt = function($con, $id) {
		$sql = 'SELECT * FROM home_owner_debt WHERE id = ' . $id;
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$result = mysqli_fetch_array($results);
			$homeOwnerDebt = new HomeOwnerDebt();
			$homeOwnerDebt->setId(result[0]);
			$homeOwnerDebt->setHoId($dbio->select($readHo(result[1])));
			$homeOwnerDebt->setDebterId($dbio->select($readDebter(result[2])));
			$homeOwnerDebt->setMonthlyPayment(result[3]);
			$homeOwnerDebt->setBalance(result[4]);
		} else {
			$homeOwnerDebt = false;
		}
		return $homeOwnerDebt;
	};

	$updateHomeOwnerDebt = function($con, $homeOwnerDebt) {
		$sql = 'UPDATE home_owner_debt SET ';
		$sql .= 'id = ' . $home_owner_debt->getId() . ', ';
		$sql .= 'ho_id = ' . $home_owner_debt->getHoId() . ', ';
		$sql .= 'debter_id = ' . $home_owner_debt->getDebterId() . ', ';
		$sql .= 'monthly_payment = ' . $home_owner_debt->getMonthlyPayment() . ', ';
		$sql .= 'balance = ' . $home_owner_debt->getBalance() ;
		$sql .= 'WHERE id = ' . id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$deleteHomeOwnerDebt = function($con, $id) {
		$sql = 'DELETE FROM home_owner_debt WHERE id = ' . $id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$listHomeOwnerDebt = function($con) {
		$sql = 'SELECT * FROM home_owner_debt';
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$homeOwnerDebts = array();
			while ($result = mysqli_fetch_array($results)) {
				$homeOwnerDebt = new HomeOwnerDebt();
				$homeOwnerDebt->setId(result[0]);
				$homeOwnerDebt->setHoId($dbio->select($readHo(result[1])));
				$homeOwnerDebt->setDebterId($dbio->select($readDebter(result[2])));
				$homeOwnerDebt->setMonthlyPayment(result[3]);
				$homeOwnerDebt->setBalance(result[4]);
				$homeOwnerDebts[] = homeOwnerDebt;
			}// end while
		} else {
			$homeOwnerDebts = false;
		}
		return $homeOwnerDebts;
	};

